package servlet.user;

import dao.UserDao;
import entity.User;
import util.R;
import util.ResposeUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

public class RegisterServlet extends HttpServlet {
    private UserDao userDao = new UserDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, String[]> parameterMap = req.getParameterMap();
        System.out.println(parameterMap.toString());
//        ResposeUtil.write(parameterMap,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            User user = new User();
            int insert = userDao.insert(user);
            if (insert>0) {
                ResposeUtil.write(new R(200,null),resp);
            } else {
                ResposeUtil.write(new R(R.CODE_ERR,null,R.MSG_ERR),resp);
            }
        }catch (Exception e) {
            ResposeUtil.write(new R(R.CODE_SYS_ERR,null,R.MSG_SYS_ERR),resp);
        }

    }
}
